#include <cstdio>
#include <cmath>
#include <queue>

using namespace std;

double f[ 1001 ][ 1001 ], d[ 1001 ];
int n;

bool relax( int u, int v )
{
    if ( d[ u ] + f[ u ][ v ] < d[ v ] )
    {
        d[ v ] = d[ u ] + f[ u ][ v ];
        return true;
    }
    return false;
}

void spfa( int p )
{
    int i, u;
    queue<int> q;
    for ( i = 0; i < n; i++ )
        d[ i ] = 0xfffffff;
    d[ p ] = 0;
    q.push( p );
    while ( !q.empty( ) )
    {
        u = q.front( );
        q.pop( );
        for ( i = 0; i < n; i++ )
            if ( relax( u, i ) )
                q.push( i );
    }
}

int main( )
{
    int q, i, j, k, a, b;
    double t;
    while ( scanf("%d", &n) != EOF )
    {
        for ( i = 0; i < n; i++ )
            for ( j = 0; j < n; j++ )
            {
                scanf("%lf", &t);
                if ( t == 0 )
                    f[ i ][ j ] = 0xfffffff;
                else
                    f[ i ][ j ] = -log10( t );
            }
        scanf("%d", &q);
        for ( i = 0; i < q; i++ )
        {
            scanf("%d%d", &a, &b);
            a--; b--;
            spfa( a );
            if ( d[ b ] == 0xfffffff )
                printf("What a pity!\n");
            else
                printf("%.3lf\n", pow( 10.0, -d[ b ] ));
        }
    }
    return 0;
}
